package org.example.gradleauth.feigns.fallback;

import gradle.common.core.mode.entity.SystemPermissions;
import gradle.common.core.mode.entity.SystemUser;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.example.gradleauth.feigns.service.GradleAdminFeignClient;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;

/**
 * fallback
 */
@Slf4j
@Component
public class GradleAdminFallbackFactory implements FallbackFactory<GradleAdminFeignClient> {

    @Override
    public GradleAdminFeignClient create(Throwable cause) {

        return new GradleAdminFeignClient() {

            @Override
            public SystemUser loadUserByUsername(String username) {
                log.error("【admin-service】 GradleOrderFeignClient loadUserByUsername() exception = {}", ExceptionUtils.getStackTrace(cause));
                return null;
            }

            @Override
            public List<Long> queryIdListPermByUserId(Long id) {
                log.error("【admin-service】 GradleOrderFeignClient queryIdListPermByUserId() exception = {}", ExceptionUtils.getStackTrace(cause));
                return Collections.emptyList();
            }

            @Override
            public List<SystemPermissions> queryPermAll() {
                log.error("【admin-service】 GradleOrderFeignClient queryPermAll() exception = {}", ExceptionUtils.getStackTrace(cause));
                return Collections.emptyList();
            }
        };
    }
}
